package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsVideoItems;
import com.jeegit.ecms.service.ICmsVideoItemsService;
import com.jeegit.ecms.utils.ECMSUtils;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 视频清单Controller
 * 
 * @author jeegit
 * @date 2022-07-02
 */
@Controller
@RequestMapping("/ecms/videoitems")
public class CmsVideoItemsController extends BaseController
{
    private String prefix = "ecms/videoitems";

    @Autowired
    private ICmsVideoItemsService cmsVideoItemsService;

    @RequiresPermissions("ecms:videoitems:view")
    @GetMapping()
    public String videoitems(CmsVideoItems cmsVideoItems, ModelMap mmap)
    {   
    	
    	
    	mmap.put("cmsVideoItems", cmsVideoItems);
    	mmap.put("listChapters", ECMSUtils.getCmsVideoChapterList(cmsVideoItems.getCmsVideoId()));
    	
        return prefix + "/videoitems";
    }

    /**
     * 查询视频清单列表
     */
    @RequiresPermissions("ecms:videoitems:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsVideoItems cmsVideoItems)
    {
        startPage();
        List<CmsVideoItems> list = cmsVideoItemsService.selectCmsVideoItemsList(cmsVideoItems);
        return getDataTable(list);
    }

    /**
     * 导出视频清单列表
     */
    @RequiresPermissions("ecms:videoitems:export")
    @Log(title = "视频清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsVideoItems cmsVideoItems)
    {
        List<CmsVideoItems> list = cmsVideoItemsService.selectCmsVideoItemsList(cmsVideoItems);
        ExcelUtil<CmsVideoItems> util = new ExcelUtil<CmsVideoItems>(CmsVideoItems.class);
        return util.exportExcel(list, "视频清单数据");
    }

    /**
     * 新增视频清单
     */
    @GetMapping("/add")
    public String add(CmsVideoItems cmsVideoItems, ModelMap mmap)
    {
    	   mmap.put("cmsVideoItems", cmsVideoItems);
    	   mmap.put("listChapters", ECMSUtils.getCmsVideoChapterList(cmsVideoItems.getCmsVideoId()));
        return prefix + "/add";
    }

    /**
     * 新增保存视频清单
     */
    @RequiresPermissions("ecms:videoitems:add")
    @Log(title = "视频清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsVideoItems cmsVideoItems)
    {
        return toAjax(cmsVideoItemsService.insertCmsVideoItems(cmsVideoItems));
    }

    /**
     * 修改视频清单
     */
    @RequiresPermissions("ecms:videoitems:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsVideoItems cmsVideoItems = cmsVideoItemsService.selectCmsVideoItemsById(id);
        mmap.put("cmsVideoItems", cmsVideoItems);
        mmap.put("listChapters", ECMSUtils.getCmsVideoChapterList(cmsVideoItems.getCmsVideoId()));
        return prefix + "/edit";
    }

    /**
     * 修改保存视频清单
     */
    @RequiresPermissions("ecms:videoitems:edit")
    @Log(title = "视频清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsVideoItems cmsVideoItems)
    {
        return toAjax(cmsVideoItemsService.updateCmsVideoItems(cmsVideoItems));
    }

    /**
     * 删除视频清单
     */
    @RequiresPermissions("ecms:videoitems:remove")
    @Log(title = "视频清单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsVideoItemsService.deleteCmsVideoItemsByIds(ids));
    }
}
